const fs = require("fs");
let webpack = require("webpack");
let UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
// let path = require("path");
module.exports = {
  // 修改的配置
  // 将baseUrl: '/api',改为baseUrl: '/',
  // baseUrl: "/",
  publicPath:
    process.env.NODE_ENV === "production"
      ? "//x.ihuada.com/addons/wgsappointment/"
      : "/",
  devServer: {
    // port: 8083,
    proxy: {
      "/api": {
        target: "https://www.ihuada.com",
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          "^/api": "/"
        }
      }
    }
  },
  productionSourceMap: false,
  css: {
    // 是否使用css分离插件 ExtractTextPlugin
    extract: process.env.NODE_ENV === "production" ? true : false,
    // 开启 CSS source maps?
    sourceMap: true,
    // css预设器配置项
    loaderOptions: {
      sass: {
        data: fs.readFileSync("src/assets/css/common.scss", "utf-8")
      }
    },
    // 启用 CSS modules for all css / pre-processor files.
    modules: false
  },
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      }),
      new CompressionWebpackPlugin({
        asset: "[path].gz[query]",
        algorithm: "gzip",
        test: /\.js$|\.html$/,
        threshold: 10240, //对超过10kb的文件进行压缩
        // deleteOriginalAssets: true, //不删除源文件，不建议删除源文件
        minRatio: 0.8
      })
    ],
    optimization: {
      minimizer: [
        new UglifyJsPlugin({
          uglifyOptions: {
            compress: {
              warnings: false,
              drop_console: true, //console
              drop_debugger: false,
              pure_funcs: ["console.log"] //移除console
            }
          }
        })
      ]
    },
    resolve: {
      alias: {
        vue$: "vue/dist/vue.esm.js" //从Compiler版本修改为Runtime版本
      }
    }
  }
};
